﻿<%@ taglib prefix='c' uri='http://java.sun.com/jsp/jstl/core'%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ page import="com.cxx.purchasecharge.component.utils.ComponentConstants" %>
<%@ page import="com.cxx.purchasecharge.component.utils.MessageProperties" %>
<%@ page import="com.cxx.purchasecharge.core.model.OrderTypeCode" %>
<%@ page import="com.cxx.purchasecharge.component.bean.TimeFrame"%>

<style type="text/css">
	.css-dlg-outorder input, .css-dlg-outorder select
	{
		width: 150px;
	}
	#dlg-outorder-view input, #dlg-outorder-view select
	{
		width: 150px;
		border: none;
	}
	.css-dlg-outorder
	{
		float: left;
		width: 300px;
	}
	.css-dlg-outorder label
	{
		width: 80px;
	}
	#div-outorder-typecode input 
	{
		width: auto;
	}
	#div-outorder-typecode label 
	{
		cursor: pointer;
	}
</style>

<script type="text/javascript">
    var editIndex = undefined;
    function endEditing(){
        if (editIndex == undefined){return true;}
        if ($('#dg-outorderItem-new').datagrid('validateRow', editIndex)){
            var ed = $('#dg-outorderItem-new').datagrid('getEditor', {index:editIndex,field:'goodsId'});
			if(ed) 
			{
				var productname = $(ed.target).combobox('getText');
				$('#dg-outorderItem-new').datagrid('getRows')[editIndex]['name'] = productname;
				$('#dg-outorderItem-new').datagrid('endEdit', editIndex);
			}
            editIndex = undefined;
            return true;
        } else {
            return false;
        }
    }
    function onClickRow(index){
        if (editIndex != index){
            if (endEditing()){
                $('#dg-outorderItem-new').datagrid('selectRow', index)
                        .datagrid('beginEdit', index);
                editIndex = index;
            } else {
                $('#dg-outorderItem-new').datagrid('selectRow', editIndex);
            }
        }
    }
    function append(){
        if (endEditing()){
			calculateItemCount (0, 0);
			
            $('#dg-outorderItem-new').datagrid('appendRow',{id:0, goodsId:'', unit:'', unitPrice:'', amount:'', sum:'', note:'', importPrice:''});
            editIndex = $('#dg-outorderItem-new').datagrid('getRows').length-1;
            $('#dg-outorderItem-new').datagrid('selectRow', editIndex)
                    .datagrid('beginEdit', editIndex);
        }
    }
    function removeit(){
        if (editIndex == undefined){return;}
        $('#dg-outorderItem-new').datagrid('cancelEdit', editIndex)
                .datagrid('deleteRow', editIndex);
        editIndex = undefined;
		
		calculateItemCount (0, 0);
    }
    function accept(){
        if (endEditing()){
            $('#dg-outorderItem-new').datagrid('acceptChanges');
            var allRows = $('#dg-outorderItem-new').datagrid('getRows');
            //console.log(allRows.length+' rows in current page!');
            var orderItemList = "";
            for(var i = 0; i < allRows.length; i++) 
            {
    	        //console.log(allRows[i]);
            	var orderItem = "";
    	        var item = allRows[i];
    	        orderItem += (item.id +","+item.goodsId+","+item.unit+","+item.unitPrice+","+item.amount+","+item.note+","+ item.sum+","+ item.importPrice);
    	        orderItemList += orderItem + ";"
            }
            //console.log(orderItemList.substring(0, orderItemList.length-1));
            $('#outorderItemList').val(orderItemList);
        }
    }
    function reject(){
        $('#dg-outorderItem-new').datagrid('rejectChanges');
        editIndex = undefined;
    }
    function getChanges(){
        var allRows = $('#dg-outorderItem-new').datagrid('getChanges');
        console.log(allRows.length+' rows are changed!');
        for(var i = 0; i < allRows.length; i++) 
        {
	        console.log(allRows[i]);
        }
    }
    
    // order item
    function onSelectGoods (record) 
    {
    	//var goods = JSON.stringify(record);
		//console.log("editIndex--->" + editIndex);
		if (editIndex != undefined)
		{
			var importPriceEditor = $('#dg-outorderItem-new').datagrid('getEditor', {index:editIndex, field:'importPrice'});
			importPriceEditor.target.val(record.importPrice);
			
			var unitEditor = $('#dg-outorderItem-new').datagrid('getEditor', {index:editIndex, field:'unit'});
			unitEditor.target.val(record.unitBean.name);
			var unitPriceEditor = $('#dg-outorderItem-new').datagrid('getEditor', {index:editIndex, field:'unitPrice'});
			unitPriceEditor.target.numberbox('setValue', record.retailPrice);
			// get latest goods retail price for specific customer
			var customerId = $('#dlg-outorder-new #fm-outorder #customerId').combobox('getValue');
			$.post('<c:url value='/outOrder/getLatestGoodsUnitPrice.html' />', {customerId:customerId, goodsId:record.id}, 
					function(result) 
					{
						var latestOrderItem = result;
						if(latestOrderItem != '') 
						{
							unitPriceEditor.target.numberbox('setValue', latestOrderItem.unitPrice);
						}
					}, 
				'json');
			
			var allRows = $('#dg-outorderItem-new').datagrid('getRows');
			if(allRows.length > 1) 
			{
				for(var i = 0; i < allRows.length; i++) 
				{
					var item = allRows[i];
					if(record.id == item.goodsId) 
					{
						$.messager.alert('警告','不要选择重复的货物!','warning');
						$('#dlg-buttons-outorder-new #save-outorder-btn').linkbutton('disable');
						return;
					}
				}
			}
			
			// check storage whether is enough
			if('OUT' == outorder_typeCode) 
			{
				var currentStock = record.storageBean.currentStock;
				if(currentStock == 0) 
				{
					$.messager.alert('警告',record.name + '当前库存为0!','warning');
					$('#dlg-buttons-outorder-new #save-outorder-btn').linkbutton('disable');
					return;
				}
				var amountEditor = $('#dg-outorderItem-new').datagrid('getEditor', {index:editIndex, field:'amount'});
				var amount = amountEditor.target.numberbox('getValue');
				if(amount > currentStock) 
				{
					$.messager.alert('警告','当前库存不足!','warning');
					amountEditor.target.numberbox('setValue', 0);
					$('#dlg-buttons-outorder-new #save-outorder-btn').linkbutton('disable');
					return;
				}
			}
			$('#dlg-buttons-outorder-new #save-outorder-btn').linkbutton('enable');
		}
    }
	function onChangeAmount (newValue, oldValue) 
	{
		//console.log("newValue-->"+newValue + " oldValue-->"+oldValue);
		if (editIndex != undefined)
		{
			if(newValue != '') 
			{
				var goodsAmount = parseInteger(newValue.trim());
				// check storage whether is enough
				if('OUT' == outorder_typeCode) 
				{
					var amountEditor = $('#dg-outorderItem-new').datagrid('getEditor', {index:editIndex, field:'amount'});
					var goodsEditor = $('#dg-outorderItem-new').datagrid('getEditor', {index:editIndex, field:'goodsId'});
					var goodsText = goodsEditor.target.combobox('getText');
					if(goodsText && goodsText.lastIndexOf(' - ') > 0) 
					{
						var currentStock = goodsText.substring(goodsText.lastIndexOf('-') + 2);
						var stockNumber = parseInteger(currentStock);
						if(goodsAmount > stockNumber) 
						{
							$.messager.alert('警告','当前库存不足!','warning');
							amountEditor.target.numberbox('setValue', 0);
							$('#dlg-buttons-outorder-new #save-outorder-btn').linkbutton('disable');
							return;
						}
					}
				}
				
				var sumEditor = $('#dg-outorderItem-new').datagrid('getEditor', {index:editIndex, field:'sum'});
				var unitPriceEditor = $('#dg-outorderItem-new').datagrid('getEditor', {index:editIndex, field:'unitPrice'});
				var unitPrice = unitPriceEditor.target.val();
				sumEditor.target.numberbox('setValue', unitPrice * newValue);
				
				calculateItemCount (newValue, unitPrice * newValue);
				$('#dlg-buttons-outorder-new #save-outorder-btn').linkbutton('enable');
			}
		}
	}
	function onChangeUnitPrice (newValue, oldValue) 
	{
		//console.log("newValue-->"+newValue + " oldValue-->"+oldValue);
		if (editIndex != undefined)
		{
			var importPriceEditor = $('#dg-outorderItem-new').datagrid('getEditor', {index:editIndex, field:'importPrice'});
			var importPrice = parseNumber(importPriceEditor.target.val());
			if(newValue < importPrice) 
			{
				$.messager.alert('警告','单价不能低于进货价!','warning');
				$('#dlg-buttons-outorder-new #save-outorder-btn').linkbutton('disable');
				return;
			}
			$('#dlg-buttons-outorder-new #save-outorder-btn').linkbutton('enable');
		
			var sumEditor = $('#dg-outorderItem-new').datagrid('getEditor', {index:editIndex, field:'sum'});
			var amountEditor = $('#dg-outorderItem-new').datagrid('getEditor', {index:editIndex, field:'amount'});
			var amount = amountEditor.target.val();
			sumEditor.target.numberbox('setValue', amount * newValue);
			
			calculateItemCount (amount, amount * newValue);
		}
	}
	function calculateItemCount (amount, sum) 
	{
		// 计算合计在页脚
		var allRows = $('#dg-outorderItem-new').datagrid('getRows');
		var totalAmount = 0;
		var totalSum = 0;
		for(var i = 0; i < allRows.length; i++) 
		{
			var item = allRows[i];
			if(item.goodsId != '') 
			{
				totalAmount += parseInt(item.amount);
				totalSum += parseFloat(item.sum);
			}
		}
		if(amount > 0 && sum > 0) 
		{
			totalAmount += parseInt(amount);
			totalSum += parseFloat(sum);
		}
		$('#dlg-outorder-new #fm-outorder #dg-outorderItem-new').datagrid('reloadFooter',[{goodsId:'合计', amount:totalAmount, sum:totalSum}]);
		calculateDiscount (sum);
	}
	function calculateDiscount (sum) 
	{
		var allRows = $('#dg-outorderItem-new').datagrid('getRows');
		if(allRows.length > 0) 
		{
			var totalSum = 0;
			for(var i = 0; i < allRows.length; i++) 
			{
				var item = allRows[i];
				if(item.goodsId != '') 
				{
					totalSum += parseFloat(item.sum);
				}
			}
			if(sum > 0) 
			{
				totalSum += sum;
			}
			var value = $('#dlg-outorder-new #fm-outorder #discount').numberbox('getValue');
			var receivable = value * totalSum;
			$('#dlg-outorder-new #fm-outorder #receivable').numberbox('setValue', receivable);
		}
		else 
		{
			$('#dlg-outorder-new #fm-outorder #receivable').numberbox('setValue', 0);
		}
	}
    
    var newOrderCallback = function () 
    {
    	$('#dg-outorderItem-new').datagrid('loadData', []);
    	$('#dg-outorderItem-new').datagrid('reloadFooter', []);
    	$('#dlg-outorder-new #fm-outorder #userOperated').val('${sessionScope.login_user.userId}');
    	$('#dlg-outorder-new #fm-outorder #operateUserFullName').val('${sessionScope.login_user.fullName}');
    	//$('#dlg-buttons-outorder #save-outorder-btn').linkbutton('enable');
		$('#dlg-outorder-new #fm-outorder #outorder-typeCode').val(outorder_typeCode);
		$('#dlg-outorder-new #fm-outorder #discount').numberspinner('setValue', 1.00); 
		$('#dlg-outorder-new #fm-outorder #paidMoney').numberbox('setValue', 0); 
    }
    
    var viewOrderCallback = function () 
    {
		var order = $('#dg-outorder').datagrid('getSelected');
		if(order.customerBean) 
		{
			$('#dlg-outorder-view #fm-outorder #customerId').val(order.customerBean.id);
			$('#dlg-outorder-view #fm-outorder #customerName').val(order.customerBean.shortName);
		}
		if(order.contactBean) 
		{
			$('#dlg-outorder-view #fm-outorder #contactName').val(order.contactBean.name);
			$('#dlg-outorder-view #fm-outorder #contactPhone').val(order.contactBean.phone);
		}
		
		if(order.statusCode == 'NEW') 
		{
			$('#dlg-outorder-view #fm-outorder #statusCode').val('新建');
		}
		else if(order.statusCode == 'FINISHED') 
		{
			$('#dlg-outorder-view #fm-outorder #statusCode').val('完成');
		}
		else if(order.statusCode == 'CANCEL') 
		{
			$('#dlg-outorder-view #fm-outorder #statusCode').val('取消');
		}
    	//$('#dg-outorderItem-view').datagrid('load', {orderId : $('#dg-outorder').datagrid('getSelected').id});
		loadGridData ('#dlg-outorder-view #dg-outorderItem-view', '<c:url value='/outOrder/getOrderItemByOrderId.html' />', {orderId : order.id});
		//loadGridData ('#dg-outorderPay', '<c:url value='/outOrder/getOrderPayByOrderId.html' />', {orderId : order.id});
    	//$('#dg-outorderPay').datagrid('load', {orderId : $('#dg-outorder').datagrid('getSelected').id});
    	//$('#dlg-buttons-outorder #save-outorder-btn').linkbutton('disable');
		$('#dlg-outorder-view #order-id-span').html(order.id);
    }
    
    var updatePaidCallback = function () 
    {
    	var orderSelected = $('#dg-outorder').datagrid('getSelected');
    	var paidMoney = orderSelected.paidMoney;
    	var dealMoney = orderSelected.dealMoney;
    	if(paidMoney >= dealMoney) 
    	{
			$('#dlg-update-paid').dialog('close');
			//showSuccessMsg ('Payment has done.');
    	}
    	else 
    	{
    		$('#dlg-update-paid #paidMoney').numberbox('setValue', dealMoney-paidMoney);
    	}
    }
    
    function gotoPrintDialog () 
    {
    	//$('#dlg-outorder-view').dialog('close');
		var order = $('#dg-outorder').datagrid('getSelected');
		
		// fill print order header and footer for edit
		var createDate = order.createTime.substring(0, 10);
		$('#div-print-outorder-edit #div-outorder-header #customer').html(order.customerBean.shortName);
		if(order.contactBean) 
		{
			$('#div-print-outorder-edit #div-outorder-header #contact').val(order.contactBean.name);
			$('#div-print-outorder-edit #div-outorder-header #phone').val(order.contactBean.phone);
			$('#div-print-outorder-edit #div-outorder-header #address').val(order.contactBean.address);
		}
		$('#div-print-outorder-edit #div-outorder-header #createDate').html(createDate);
		$('#div-print-outorder-edit #div-outorder-header #orderId').html(order.id);
		$('#div-print-outorder-edit #div-outorder-footer #user').html(order.userSignedTo);
		
		$('#div-print-outorder #div-outorder-header #customer').html(order.customerBean.shortName);
		$('#div-print-outorder #div-outorder-header #createDate').html(createDate);
		$('#div-print-outorder #div-outorder-header #orderId').html(order.id);
		$('#div-print-outorder #div-outorder-footer #user').html(order.userSignedTo);
		
		if('OUT' == outorder_typeCode)
		{
			$('#div-print-outorder-edit #div-print-outorder-title #titleHeader').val('<%=MessageProperties.getConfig (ComponentConstants.PRINT_ORDER_HEADER)%>');
			$('#div-print-outorder-edit #div-print-outorder-title #titleSpan').html('销售出货单');
		}
		else 
		{
			$('#div-print-outorder-edit #div-print-outorder-title #titleHeader').val('<%=MessageProperties.getConfig (ComponentConstants.PRINT_ORDER_HEADER)%>');
			$('#div-print-outorder-edit #div-print-outorder-title #titleSpan').html('销售退货单');
		}
		
		// fill print order table
    	var requestUrl = '<c:url value='/outOrder/getOrderItemByOrderId.html' />';
    	var param = {orderId : order.id};
    	$.post(requestUrl, param,
    			function(result) 
    			{
    				//console.log(result);
    				var tableHtml = "<table border='1px' style='width:100%; border-collapse:collapse;'>";
					
					var tableHead = "<thead><tr align='left'>";
					tableHead += "<th width='25%'>" + "货物名" + "</th>";
					tableHead += "<th width='10%'>" + "单位" + "</th>";
					tableHead += "<th width='15%'>" + "单价" + "</th>";
					tableHead += "<th width='10%'>" + "数量" + "</th>";
					tableHead += "<th width='15%'>" + "金额" + "</th>";
					tableHead += "<th width='25%'>" + "备注" + "</th>";
					tableHead += "</tr></thead>";
					tableHtml += tableHead;
					
					var tableBody = "<tbody>";
    				for(var i = 0; i < result.rows.length; i++) 
    				{
    					var orderItem = result.rows[i];
    					//console.log(orderItem);
	    				var tr = "";
    					tr += "<tr>";
    					tr += "<td>" + orderItem.goodsName + "</td>";
    					tr += "<td>" + orderItem.goodsUnit + "</td>";
    					tr += "<td>" + orderItem.unitPrice + "</td>";
    					tr += "<td>" + orderItem.amount + "</td>";
    					tr += "<td>" + orderItem.sum + "</td>";
    					tr += "<td>" + orderItem.comment + "</td>";
    					tr += "</tr>";
    					tableBody += tr;
    				}
					tableBody += "</tbody>";
					tableHtml += tableBody;
					
					var tableFooter = "<tfoot style='font-weight:bold; font-style:italic;'>";
					for(var i = 0; i < result.footer.length; i++) 
    				{
						var orderCount = result.footer[i];
    					//console.log(orderCount);
	    				var tr = "";
    					tr += "<tr>";
    					tr += "<td>" + "" + "</td>";
    					tr += "<td>" + "" + "</td>";
    					tr += "<td>" + "合计" + "</td>";
    					tr += "<td>" + orderCount.amount + "</td>";
    					tr += "<td>" + orderCount.sum + "</td>";
						tr += "<td>" + "" + "</td>";
    					tr += "</tr>";
    					tableFooter += tr;
					}
					tableFooter += "</tfoot>";
					tableHtml += tableFooter;
					
   					tableHtml += "</table>";
   					//console.log (tableHtml);
   					var $table = $('#div-print-outorder #outorder-table table');
					if($table.get(0)) 
					{
						$table.replaceWith($(tableHtml));
					}
					else 
					{
						$('#div-print-outorder #outorder-table').append($(tableHtml));
					}
					var $table2 = $('#div-print-outorder-edit #outorder-table table');
					if($table2.get(0)) 
					{
						$table2.replaceWith($(tableHtml));
					}
					else 
					{
						$('#div-print-outorder-edit #outorder-table').append($(tableHtml));
					}
					$('#dlg-print-outorder').dialog('open');
    			}, 
    			'json');
    }
	
	function printOrder () 
    {
		var titleHeader = $('#div-print-outorder-edit #div-print-outorder-title #titleHeader').val();
		var titleSpan = $('#div-print-outorder-edit #div-print-outorder-title #titleSpan').html();
		$('#div-print-outorder #div-print-outorder-title').html(titleHeader + titleSpan);
	
		var contact = $('#div-print-outorder-edit #div-outorder-header #contact').val();
		var phone = $('#div-print-outorder-edit #div-outorder-header #phone').val();
		var address = $('#div-print-outorder-edit #div-outorder-header #address').val();
		var attachment = $('#div-print-outorder-edit #div-outorder-footer #attachment').val();
		
		$('#div-print-outorder #div-outorder-header #contact').html(contact);
		$('#div-print-outorder #div-outorder-header #phone').html(phone);
		$('#div-print-outorder #div-outorder-header #address').html(address);
		$('#div-print-outorder #div-outorder-footer #attachment').html(attachment);
	
		$('#div-print-outorder').print();
	}
	
	
	
	function newOutOrder() 
	{
		if('OUT' == outorder_typeCode) 
		{
			newModel('#dlg-outorder-new', '新增销售出货单', '#fm-outorder', '<c:url value='/outOrder/newOrder.html' />', newOrderCallback);
		}
		else 
		{
			newModel('#dlg-outorder-new', '新增销售退货单', '#fm-outorder', '<c:url value='/outOrder/newOrder.html' />', newOrderCallback);
		}
		$('#dlg-outorder-new #tb-outorderList #btn-add-orderItem').linkbutton('disable');
		$('#dlg-outorder-new #tb-outorderList #btn-delete-orderItem').linkbutton('disable');
		$('#dlg-buttons-outorder-new #save-outorder-btn').linkbutton('disable');
	}
	function viewOutOrder()
	{
		if('OUT' == outorder_typeCode) 
		{
			var selectedRow = $('#dg-outorder').datagrid('getSelected');
			if(selectedRow) 
			{
				editModel('#dg-outorder', '#dlg-outorder-view', '查看销售出货单', '#fm-outorder', '', viewOrderCallback);
				return;
			}
			var checkedRows = $('#dg-outorder').datagrid('getChecked');
			if (checkedRows.length >= 1) 
			{
				var orderIds = "";
				for(var i = 0; i < checkedRows.length; i++) 
				{
					orderIds += (checkedRows[i].id + ";");
				}
				orderIds = orderIds.substring(0, orderIds.length-1);
				
				$('#dlg-multi-outorder-view').dialog('open').dialog('setTitle', '销售出货对账单');
				loadGridData ('#dlg-multi-outorder-view #dg-outorderItem-view', '<c:url value='/outOrder/getOrderItemsByOrderIds.html' />', {orderIds : orderIds});
			}
		}
		else 
		{
			var selectedRow = $('#dg-outorder').datagrid('getSelected');
			if(selectedRow) 
			{
				editModel('#dg-outorder', '#dlg-outorder-view', '查看销售退货单', '#fm-outorder', '', viewOrderCallback);
				return;
			}
			var checkedRows = $('#dg-outorder').datagrid('getChecked');
			if (checkedRows.length >= 1) 
			{
				var orderIds = "";
				for(var i = 0; i < checkedRows.length; i++) 
				{
					orderIds += (checkedRows[i].id + ";");
				}
				orderIds = orderIds.substring(0, orderIds.length-1);
				
				$('#dlg-multi-outorder-view').dialog('open').dialog('setTitle', '销售退货对账单');
				loadGridData ('#dlg-multi-outorder-view #dg-outorderItem-view', '<c:url value='/outOrder/getOrderItemsByOrderIds.html' />', {orderIds : orderIds});
			}
		}
	}
	function deleteOutOrder()
	{
		if('OUT' == outorder_typeCode) 
		{
			destroyMultipleModel('#dg-outorder', '销售出货单', '<c:url value='/outOrder/delOrder.html' />');
		}
		else 
		{
			destroyMultipleModel('#dg-outorder', '销售退货单', '<c:url value='/outOrder/delOrder.html' />');
		}
	}
	function updateOutOrderStatus() 
	{
		if('OUT' == outorder_typeCode) 
		{
			editModel('#dg-outorder', '#dlg-update-status', '编辑销售出货单状态', '#fm-outorder', '<c:url value='/outOrder/updateStatus.html' />');
		}
		else 
		{
			editModel('#dg-outorder', '#dlg-update-status', '编辑销售退货单状态', '#fm-outorder', '<c:url value='/outOrder/updateStatus.html' />');
		}
		var row = $('#dg-outorder').datagrid('getSelected');
		if(row) 
		{
			$('#dlg-update-status #fm-outorder #customerName').val(row.customerBean.shortName);
		}
	}
	
	var onChangeDiscount = function(value)
	{
		accept ();
		calculateDiscount (0);
	}
	var onClickOutOrderRow = function (rowIndex, rowData) 
	{
		$('#toolbar-outorder #btn-viewOutorder').linkbutton('enable');
		//$('#toolbar-outorder #btn-deleteOutorder').linkbutton('enable');
		if('OUT' == outorder_typeCode) 
		{
			if(rowData.statusCode == 'NEW') 
			{
				$('#toolbar-outorder #btn-editStatus').linkbutton('enable');
			}
			else 
			{
				$('#toolbar-outorder #btn-editStatus').linkbutton('disable');
			}
		}
	}
	var onLoadOutOrderSuccess = function (data) 
	{
		$('#toolbar-outorder #btn-viewOutorder').linkbutton('disable');
		$('#toolbar-outorder #btn-deleteOutorder').linkbutton('disable');
		$('#toolbar-outorder #btn-editStatus').linkbutton('disable');
	}
	var onCheckAllOutOrder = function(rows) 
	{
		$('#toolbar-outorder #btn-deleteOutorder').linkbutton('enable');
		$('#toolbar-outorder #btn-viewOutorder').linkbutton('enable');
	}
	var onUnCheckOutOrder = function(rowIndex,rowData) 
	{
		var rows = $('#dg-outorder').datagrid('getChecked');
		if (rows.length == 0) {
			$('#toolbar-outorder #btn-deleteOutorder').linkbutton('disable');
			$('#toolbar-outorder #btn-viewOutorder').linkbutton('disable');
		}
	}
	
	var onSelectCustomer = function(record) 
	{
		//$('#dlg-outorder-new #fm-outorder #customerId').val(record.id);
		$('#dlg-outorder-new #fm-outorder #userSignedTo').val(record.userSignedTo);
		if(record.contactBeans.length > 0) 
		{
			$('#dlg-outorder-new #fm-outorder #contactId').val(record.contactBeans[0].id);
			$('#dlg-outorder-new #fm-outorder #contactName').val(record.contactBeans[0].name);
		}
		else 
		{
			$('#dlg-outorder-new #fm-outorder #contactId').val('');
			$('#dlg-outorder-new #fm-outorder #contactName').val('');
		}
		$('#dlg-outorder-new #tb-outorderList #btn-add-orderItem').linkbutton('enable');
		$('#dlg-outorder-new #tb-outorderList #btn-delete-orderItem').linkbutton('enable');
	}
	var onChangeCustomer = function(newValue, oldValue) 
	{
		if(newValue == undefined) 
		{
			$('#dlg-outorder-new #fm-outorder #userSignedTo').val('');
			$('#dlg-outorder-new #fm-outorder #contactId').val('');
			$('#dlg-outorder-new #fm-outorder #contactName').val('');
			$('#dlg-outorder-new #tb-outorderList #btn-add-orderItem').linkbutton('disable');
			$('#dlg-outorder-new #tb-outorderList #btn-delete-orderItem').linkbutton('disable');
		}
	}
	var onSearchOrderById = function () 
	{
		var orderId = $('#toolbar-outorder #orderIdSearchSpan #orderId').val();
		if(orderId != '') 
		{
			var pageOptions = $('#dg-outorder').datagrid('getPager').data("pagination").options;
			var page = pageOptions.pageNumber;
			var rows = pageOptions.pageSize;
			loadGridData ('#dg-outorder', '<c:url value='/outOrder/getAll.html' />', {page:page, rows:rows, sort:'<%=ComponentConstants.CREATE_TIME %>', order:'asc', type:outorder_typeCode, orderId:orderId});
		}
		else 
		{
			$.messager.alert('警告','请填写查询条件!','warning');
		}
	}
	var onSelectStartDate = function (date) 
	{
		$('#toolbar-outorder #advanceSearchSpan #timeFrame').combobox('setValue', 'CUSTOMIZE');
	}
	var onSelectTimeFrame = function(record) 
	{
		var startDate = generateStartDate(record.value);
		var endDate = new Date().format("yyyy-MM-dd");
		$('#toolbar-outorder #advanceSearchSpan #startDate').datebox('setValue', startDate);
		$('#toolbar-outorder #advanceSearchSpan #endDate').datebox('setValue', endDate);
	}
	var outorder_typeCode = 'OUT';
	var outorder_sortOrder = {sort:'<%=ComponentConstants.CREATE_TIME %>', order:'desc'};
	$(document).ready(function(){
	});
	var getSelectedOutOrderTypeCode = function() 
	{
		var $typeCode = document.getElementsByName("outorder_typeCode_mode");
		for(var i = 0; i < $typeCode.length; i ++) 
		{
			if($typeCode[i].checked) 
			{
				outorder_typeCode = $typeCode[i].value;
				break;
			}
		}
		//console.log('outord typecode --- ' + outorder_typeCode);
	}
	function loadPagingGridData(datagridId, requestUrl, searchKey, sortField, sortOrder) 
	{
		var pageOptions = $(datagridId).datagrid('getPager').data("pagination").options;
		var page = pageOptions.pageNumber;
		var rows = pageOptions.pageSize;
		getSelectedOutOrderTypeCode();
		//loadGridData (datagridId, requestUrl, {page:page, rows:rows, searchKey:searchKey, sort:sortField, order:sortOrder, type:outorder_typeCode});
		loadGridData2(datagridId, {type:outorder_typeCode});
	}
	var onSelectOutOrderTypeCode = function(radioBtnId) 
	{
		var $typeCode = document.getElementsByName("outorder_typeCode_mode");
		var typeCode;
		for(var i = 0; i < $typeCode.length; i ++) 
		{
			if($typeCode[i].id == radioBtnId) 
			{
				$typeCode[i].checked = true;
				$typeCode[i].click();
			}
		}
	}
	var onSearchOrderByAdvance = function (sortOrder) 
	{
		console.log('onSearchOrderByAdvance----------------');
		var startDate = $('#toolbar-outorder #advanceSearchSpan #startDate').combo('getValue');
		var endDate = $('#toolbar-outorder #advanceSearchSpan #endDate').combo('getValue');
		var customerId = $('#toolbar-outorder #advanceSearchSpan #customerId').combo('getValue');
		if((startDate != '' && endDate == '') || (startDate == '' && endDate != '')) 
		{
			$.messager.alert('警告','开始时间和结束时间必须同时填!','warning');
			return;
		}
		if(startDate == '' && endDate == '' && customerId == '') 
		{
			$.messager.alert('警告','请填写查询条件!','warning');
			return;
		}
		//var pageOptions = $('#dg-outorder').datagrid('getPager').data("pagination").options;
		//var page = pageOptions.pageNumber;
		//var rows = pageOptions.pageSize;
		
		getSelectedOutOrderTypeCode();
		loadGridData ('#dg-outorder', '<c:url value='/outOrder/getAll.html' />', {page:sortOrder.page, rows:sortOrder.rows, sort:sortOrder.sort, order:sortOrder.order, type:outorder_typeCode, startDate:startDate, endDate:endDate, customerId:customerId});
	}
	
	var onBeforeLoadOutOrder = function (param) 
	{
		//console.log('onBeforeLoadOutOrder----------------');
		//console.log(param);
		outorder_sortOrder = param;
		var startDate = $('#toolbar-outorder #advanceSearchSpan #startDate').combo('getValue');
		var endDate = $('#toolbar-outorder #advanceSearchSpan #endDate').combo('getValue');
		var customerId = $('#toolbar-outorder #advanceSearchSpan #customerId').combo('getValue');
		if(customerId == undefined) 
		{
			customerId = '';
		}
		if(startDate == '' && endDate == '' && customerId == '') 
		{
			var timeFrame = $('#toolbar-outorder #advanceSearchSpan #timeFrame').combo('getValue');
			startDate = generateStartDate(timeFrame);
			endDate = new Date().format("yyyy-MM-dd");
			$('#toolbar-outorder #advanceSearchSpan #startDate').datebox('setValue', startDate);
			$('#toolbar-outorder #advanceSearchSpan #endDate').datebox('setValue', endDate);
			
			startDate = $('#toolbar-outorder #advanceSearchSpan #startDate').combo('getValue');
			endDate = $('#toolbar-outorder #advanceSearchSpan #endDate').combo('getValue');
		}
		
		getSelectedOutOrderTypeCode();
		$('#dg-outorder').datagrid('options').url = "<c:url value='/outOrder/getAll.html' />?type="+outorder_typeCode+"&startDate="+startDate+"&endDate="+endDate+"&customerId="+customerId;
		
		return true;
	}
	
</script>

	<div id="div-outorder-typecode" style="margin-bottom:5px;">
		<input id="typeCode_out" name="outorder_typeCode_mode" type="radio" value="<%=OrderTypeCode.OUT%>" checked="checked" onclick="onSearchOrderByAdvance(outorder_sortOrder)"><label onclick="onSelectOutOrderTypeCode('typeCode_out')">销售出货</label>
		<input id="typeCode_out_return" name="outorder_typeCode_mode" type="radio" value="<%=OrderTypeCode.OUT_RETURN%>" onclick="onSearchOrderByAdvance(outorder_sortOrder)"><label onclick="onSelectOutOrderTypeCode('typeCode_out_return')">销售退货</label>
	</div>
	<div style="width:100%; height:430px;">
		<table id="dg-outorder" title="销售单管理" class="easyui-datagrid"
			toolbar="#toolbar-outorder" pagination="true" rownumbers="true" showFooter="true" 
			singleSelect="true" checkOnSelect="true" selectOnCheck="false" fit="true"  
			fitColumns="true" sortName="<%=ComponentConstants.CREATE_TIME %>" sortOrder="desc" data-options="onClickRow:onClickOutOrderRow, onLoadSuccess:onLoadOutOrderSuccess, onCheckAll:onCheckAllOutOrder, onUncheckAll:onUnCheckOutOrder, onCheck:onCheckAllOutOrder, onUncheck:onUnCheckOutOrder,onBeforeLoad:onBeforeLoadOutOrder">
			<thead>
				<tr>
					<th data-options="field:'ck',checkbox:true"></th>
					<th data-options="field:'id'"><spring:message code="order.id" /></th>
					<th field="<%=ComponentConstants.CUSTOMER_NAME %>" width="70" sortable="true" data-options="formatter:customerNameFormatter"><spring:message code="order.customer" /></th>
<%-- 					<th field="<%=ComponentConstants.DEAL_MONEY %>" width="50" sortable="true"><spring:message code="order.inDealMoney" /></th> --%>
					<th field="<%=ComponentConstants.RECEIVABLE_MONEY %>" width="50" sortable="true"><spring:message code="order.inDealMoney" /></th>
					<%-- <th field="<%=ComponentConstants.PAID_MONEY %>" width="50" sortable="true" data-options="styler:cellStyler_orderPaidMoney"><spring:message code="order.paidMoney" /></th> --%>
					<th field="<%=ComponentConstants.PROFIT_MONEY %>" sortable="true" hidden="true"><spring:message code="order.profit" /></th>
					<th field="<%=ComponentConstants.CREATE_TIME %>" width="80" sortable="true"><spring:message code="order.createDate" /></th>
					<%-- <th field="<%=ComponentConstants.PAY_TIME %>" width="50" sortable="true"><spring:message code="order.payDate" /></th> --%>
					<th field="payDeadline" width="50"><spring:message code="order.payDeadline" /></th>
					<th field="userSignedTo" width="50" sortable="true"><spring:message code="order.signUserId" /></th>
					<th field="userOperated" width="50" sortable="true">操作员</th>
					<th field="statusCode" width="50" data-options="formatter:orderStatusFormatter, align:'center'"><spring:message code="order.statusCode" /></th>
				</tr>
			</thead>
		</table>
	</div>
	
	<div id="toolbar-outorder" style="padding:5px;height:auto">
		<div>
			<a href="javascript:void(0)" class="easyui-linkbutton" 
				iconCls="icon-add" plain="true" onclick="newOutOrder()" title="新增销售单">新增销售单</a> 
			<a id="btn-viewOutorder" href="javascript:void(0)" class="easyui-linkbutton" disabled="true" 
				iconCls="icon-search" plain="true" onclick="viewOutOrder()" title="选择一行查看订单详情或勾选多行查看订单项">查看</a> 
			<a id="btn-deleteOutorder" href="javascript:void(0)" class="easyui-linkbutton" disabled="true" 
				iconCls="icon-remove" plain="true" onclick="deleteOutOrder()" title="选择一行删除订单">删除销售单</a>
			<!--<a href="javascript:void(0)" class="easyui-linkbutton"
				plain="true" onclick="editModel('#dg-outorder', '#dlg-update-paid', '新增收款', '#dlg-update-paid #fm-outorder', '<c:url value='/outOrder/updatePaid.html' />', updatePaidCallback)" title="">新增收款</a>-->
			<a id="btn-editStatus" href="javascript:void(0)" class="easyui-linkbutton" disabled="true" 
				iconCls="icon-edit" plain="true" onclick="updateOutOrderStatus()" title="选择一行编辑订单状态">编辑状态</a>
		</div>
		<!--<span style="float: right; margin-right: 5px">
			<input class="easyui-searchbox" data-options="prompt:'<spring:message code="pleaseInputValue" />',searcher:doSearchOrder" style="width:300px" />
		</span>-->
		<div>
			<span id="orderIdSearchSpan" style="width: 25%; display: inline-block; margin-left: 8px;">
				<form id="outOrderSearchForm" action="">
	            	订单号: <input id="orderId" name="orderId" class="easyui-validatebox" style="width:100px">
					<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" plain="true" title="查询出库单" onclick="onSearchOrderById()">查询</a>
				</form>
	        </span>
			<span id="advanceSearchSpan" style="width: 70%; display: inline-block;">
				<form id="outOrderSearchForm" action="">
	            	时间: <input id="startDate" name="startDate" class="easyui-datebox" style="width:100px" 
					editable="false" title="开始时间" data-options="onSelect: onSelectStartDate">
	            	- <input id="endDate" name="endDate" class="easyui-datebox" style="width:100px" 
					editable="false" title="结束时间" data-options="onSelect: onSelectStartDate">&nbsp;
					<select id="timeFrame" name="timeFrame" class="easyui-combobox" style="width:80px" panelHeight="auto" editable="false" data-options="onSelect: onSelectTimeFrame">
						<option value="CUSTOMIZE"><%=TimeFrame.CUSTOMIZE.getText () %></option>
						<option value="TODAY" selected="selected"><%=TimeFrame.TODAY.getText () %></option>
						<option value="RECENT_THREE_DAYS"><%=TimeFrame.RECENT_THREE_DAYS.getText () %></option>
						<option value="RECENT_SEVEN_DAYS"><%=TimeFrame.RECENT_SEVEN_DAYS.getText () %></option>
						<option value="RECENT_FIFTEEN_DAYS"><%=TimeFrame.RECENT_FIFTEEN_DAYS.getText () %></option>
						<option value="RECENT_THIRTY_DAYS"><%=TimeFrame.RECENT_THIRTY_DAYS.getText () %></option>
						<option value="CURRENT_MONTH"><%=TimeFrame.CURRENT_MONTH.getText () %></option>
					</select>
	            	&nbsp;
	            	客户: 
	           		<input id="customerId" name="customerId" class="easyui-combobox" style="width:100px" data-options="valueField:'id',
												textField:'shortName',
												url:'',
												onSelect: onSelectCustomer,
												mode:'local',
												filter:comboboxFilter,
												onShowPanel:onClickCustomerCombox" />
					<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" plain="true" title="查询出库单" onclick="onSearchOrderByAdvance(outorder_sortOrder)">查询</a>
				</form>
	        </span>
        </div>
	</div>

	<!-- new order dialog -->
	<div id="dlg-outorder-new" class="easyui-dialog"
		style="width: 760px; height: 480px; padding: 5px;" closed="true"
		buttons="#dlg-buttons-outorder-new" data-options="modal:true">
		<div>
			<form id="fm-outorder" class="fm" method="post" novalidate>
				<div class="divHidden">
					<input id="id" name="id" value="0">
				</div>
				<div class="divHidden">
					<input id="outorder-typeCode" name="typeCode">
				</div>
				<!-- <div class="divHidden">
					<input id="customerId" name="customerBean.id" class="easyui-validatebox" />
				</div> -->
				<div class="fitem css-dlg-outorder">
					<label><spring:message code="order.customer" />:</label> 
					<!--<input id="customerName" name="customerBean.shortName" class="easyui-validatebox" readonly="readonly" required="true" onclick="popupSearchAndSelectCustomerDialog()" title="<spring:message code="order.searchAndSelectCustomer" />" />-->
					<input id="customerId" name="customerBean.id" class="easyui-combobox" style="width:150px" data-options="valueField:'id',
											textField:'shortName',
											url:'',
											required:true,
											onSelect: onSelectCustomer,
											mode:'local',
											filter:comboboxFilter,
											onShowPanel:onClickCustomerCombox, onChange:onChangeCustomer"/>
				</div>
				<div class="fitem divHidden">
					<input id="contactId" name="contactBean.id" class="easyui-validatebox" />
				</div>
				<div class="fitem css-dlg-outorder">
					<label>联系人:</label> 
					<input id="contactName" name="contactBean.name" class="easyui-validatebox" readonly="readonly" title="不可编辑" />
				</div>
				<div class="fitem css-dlg-outorder">
					<label><spring:message code="order.signUserId" />:</label> 
					<input id="userSignedTo" name="userSignedTo" class="easyui-validatebox" readonly="readonly" title="不可编辑" required="true" />
				</div>
				<div class="fitem divHidden">
					<input id="userOperated" name="userOperated" class="easyui-validatebox" readonly="readonly" title="不可编辑" />
				</div>
				<div class="fitem css-dlg-outorder">
					<label>操作员:</label> 
					<input id="operateUserFullName" name="operateUserFullName" class="easyui-validatebox" readonly="readonly" title="不可编辑" />
				</div>
				
				<div class="divHidden">
					<input id="outorderItemList" name="orderItemList" class="easyui-validatebox" />
				</div>
				
				<table id="dg-outorderItem-new" class="easyui-datagrid" title="<spring:message code="order.items" />"
						data-options="
							rownumbers: true,
							singleSelect: true,
							toolbar: '#tb-outorderList',
							onClickRow: onClickRow,
							width:700,
							height:250,
							style:{marginBottom:10},
							showFooter: true
						">
					<thead>
						<tr>
							<th data-options="field:'id',hidden:true"></th>
							<th data-options="field:'goodsId',width:170,
									formatter:function(value,row){
										return row.name;
									},
									editor:{
										type:'combobox',
										options:{
											valueField:'id',
											textField:'nameAndCurrentStock',
											url:'',
											required:true,
											onSelect: onSelectGoods,
											mode:'local',
											filter:comboboxFilter,
											onShowPanel:onClickGoods
										}
									}"><spring:message code="order.product" /></th>
							<th data-options="field:'unit',width:50,editor:'text'"><spring:message code="order.unit" /></th>
							<th data-options="field:'unitPrice',width:80,editor:{type:'numberbox',options:{required:true, precision:2, onChange: onChangeUnitPrice}}"><spring:message code="order.unitPrice" /></th>
							<th data-options="field:'amount',width:80,editor:{type:'numberbox', options:{required:true, onChange: onChangeAmount}}"><spring:message code="order.amount" /></th>
							<th data-options="field:'sum',width:100,editor:{type:'numberbox',options:{precision:2}}"><spring:message code="order.sum" /></th>
							<th data-options="field:'note',width:160,editor:'text'"><spring:message code="order.note" /></th>
							<th data-options="field:'importPrice',hidden:true,editor:'text'"></th>
						</tr>
					</thead>
				</table>
			 
				<div id="tb-outorderList" style="height:auto">
					<a id="btn-add-orderItem" href="javascript:void(0)" class="easyui-linkbutton" disabled="true" data-options="iconCls:'icon-add',plain:true" onclick="append()"><spring:message code="order.append" /></a>
<%-- 				        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:true" onclick="accept()"><spring:message code="order.accept" /></a> --%>
					<a id="btn-delete-orderItem" href="javascript:void(0)" class="easyui-linkbutton" disabled="true" data-options="iconCls:'icon-remove',plain:true" onclick="removeit()"><spring:message code="order.remove" /></a>
				</div>
				
				<div class="fitem css-dlg-outorder">
					<label>折扣率:</label> 
					<input id="discount" name="discount" class="easyui-numberspinner" value="1.00" data-options="min:0.01,max:1.00,increment:0.02,precision:2,onChange:onChangeDiscount" style="width:150px" />
				</div>
				<div class="fitem css-dlg-outorder">
					<label>折后应付:</label> 
					<input id="receivable" name="receivable" class="easyui-numberbox" style="width:156px" data-options="precision:2" />
				</div>
				<!-- <div class="fitem css-dlg-outorder">
					<label>实付款:</label> 
					<input id="paidMoney" name="paidMoney" class="easyui-numberbox" style="width:156px" data-options="precision:2" />
				</div> -->
				<div class="fitem css-dlg-outorder" style="clear:left; width:100%;">
					<label>备注:</label>
					<input id="comment" name="comment" style="width:85%;" />
				</div>
			</form>
		</div>
	</div>
	<div id="dlg-buttons-outorder-new">
		<a href="javascript:void(0)" id="save-outorder-btn" class="easyui-linkbutton" disabled="true"
			iconCls="icon-ok" onclick="saveModel('#dg-outorder', '#dlg-outorder-new', '#fm-outorder', null, accept)"><spring:message code="save" /></a>
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel" onclick="javascript:$('#dlg-outorder-new').dialog('close')"><spring:message code="cancel" /></a>
	</div>
	
	<!-- view order dialog -->
	<div id="dlg-outorder-view" class="easyui-dialog"
		style="width: 800px; height: 500px; padding: 10px 20px" closed="true"
		buttons="#dlg-buttons-outorder-view" data-options="modal:true">
		<div class="ftitle">销售单&nbsp;-&nbsp;<span id="order-id-span"></span></div>
		<div style="">
			<form id="fm-outorder" class="fm" method="post" novalidate>
				<div class="fitem divHidden">
					<input id="id" name="id" value="0">
				</div>
				<div class="fitem divHidden">
					<input id="customerId" name="customerId" class="easyui-validatebox" />
				</div>
				<div class="fitem css-dlg-outorder">
					<label><spring:message code="order.customer" />:</label> 
					<input id="customerName" name="<%=ComponentConstants.CUSTOMER_NAME %>" class="easyui-validatebox" readonly="readonly" />
				</div>
				<div class="fitem css-dlg-outorder">
					<label>联系人:</label> 
					<input id="contactName" name="contactName" class="easyui-validatebox" readonly="readonly" />
				</div>
				<div class="fitem css-dlg-outorder">
					<label>联系电话:</label> 
					<input id="contactPhone" name="contactPhone" class="easyui-validatebox" readonly="readonly" />
				</div>
				<div class="fitem css-dlg-outorder">
					<label>操作员:</label> 
					<input id="userOperated" name="userOperated" class="easyui-validatebox" readonly="readonly" />
				</div>
				<div class="fitem css-dlg-outorder">
					<label><spring:message code="order.signUserId" />:</label> 
					<input id="userSignedTo" name="userSignedTo" class="easyui-validatebox" readonly="readonly" />
				</div>
				<div class="fitem css-dlg-outorder">
					<label>创建日期:</label> 
					<input id="<%=ComponentConstants.CREATE_TIME %>" name="<%=ComponentConstants.CREATE_TIME %>" readonly="readonly" />
				</div>
				<div class="fitem css-dlg-outorder">
					<label>状态:</label> 
					<input id="statusCode" name="statusCode" readonly="readonly" />
				</div>
				<div class="fitem css-dlg-outorder">
					<label>折扣率:</label> 
					<input id="discount" name="discount" class="easyui-validatebox" readonly="readonly" />
				</div>
				<div class="fitem css-dlg-outorder">
					<label>折后应付:</label> 
					<input id="receivable" name="receivable" class="easyui-validatebox" readonly="readonly" />
				</div>
				<div class="fitem css-dlg-outorder">
					<label>实付款:</label> 
					<input id="paidMoney" name="paidMoney" class="easyui-validatebox" readonly="readonly" />
				</div>
				<div class="fitem css-dlg-outorder" style="clear:left; width:100%;">
					<label>备注:</label>
					<input id="comment" name="comment" style="width:85%;" readonly="readonly" />
				</div>
				
				<table id="dg-outorderItem-view" class="easyui-datagrid" title="<spring:message code="order.items" />" style="width:700px;height:auto"
						data-options="
							rownumbers: true,
							singleSelect: true,
							showFooter: true,
							url: ''
						">
					<thead>
						<tr>
							<th data-options="field:'id',hidden:true"></th>
							<th data-options="field:'goodsName',width:170"><spring:message code="order.product" /></th>
							<th data-options="field:'goodsUnit',width:50"><spring:message code="order.unit" /></th>
							<th data-options="field:'<%=ComponentConstants.ORDER_UNIT_PRICE %>',width:80"><spring:message code="order.unitPrice" /></th>
							<th data-options="field:'<%=ComponentConstants.ORDER_AMOUNT %>',width:80"><spring:message code="order.amount" /></th>
							<th data-options="field:'<%=ComponentConstants.ORDER_SUM %>',width:100"><spring:message code="order.sum" /></th>
							<th data-options="field:'comment',width:160"><spring:message code="order.note" /></th>
						</tr>
					</thead>
				</table>
			</form>
		</div>
	</div>
	<div id="dlg-buttons-outorder-view">
		<a href="javascript:void(0)" id="print-outorder-btn" class="easyui-linkbutton"
			iconCls="icon-print" onclick="gotoPrintDialog ()"><spring:message code="print" /></a> 
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel" onclick="javascript:$('#dlg-outorder-view').dialog('close')"><spring:message code="cancel" /></a>
	</div>
	
	<!-- 查看多个订单 -->
	<div id="dlg-multi-outorder-view" class="easyui-dialog"
		style="width: 800px; height: 500px; padding: 10px 10px" closed="true"
		buttons="#dlg-buttons-multi-outorder-view" data-options="modal:true">
		<div style="">
			<table id="dg-outorderItem-view" class="easyui-datagrid" title="订单明细" style="width:750px;height:auto"
					data-options="
						rownumbers: true,
						singleSelect: true,
						showFooter: true,
						url: '',
		                fitColumns:true,
		                view:groupview,
		                groupField:'orderId',
		                groupFormatter:orderGroupFormatter
					">
				<thead>
					<tr>
						<th data-options="field:'id',hidden:true"></th>
						<!--<th data-options="field:'orderCreate',width:120"></th>-->
						<th data-options="field:'goodsName',width:150"><spring:message code="order.product" /></th>
						<th data-options="field:'goodsUnit',width:50"><spring:message code="order.unit" /></th>
						<th data-options="field:'<%=ComponentConstants.ORDER_UNIT_PRICE %>',width:80"><spring:message code="order.unitPrice" /></th>
						<th data-options="field:'<%=ComponentConstants.ORDER_AMOUNT %>',width:80"><spring:message code="order.amount" /></th>
						<th data-options="field:'<%=ComponentConstants.ORDER_SUM %>',width:100"><spring:message code="order.sum" /></th>
						<%-- <th data-options="field:'comment',width:160"><spring:message code="order.note" /></th> --%>
					</tr>
				</thead>
			</table>
		</div>
	</div>
	<div id="dlg-buttons-multi-outorder-view">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel" onclick="javascript:$('#dlg-multi-outorder-view').dialog('close')"><spring:message code="cancel" /></a>
	</div>
	<!-- 查看多个订单 -->
	
	<!-- update paid money -->
	<div id="dlg-update-paid" class="easyui-dialog"
		style="width: 400px; height: 300px; padding: 10px 20px" closed="true"
		buttons="#dlg-buttons-update-paid" data-options="modal:true">
		<div class="ftitle"><spring:message code="order.order" /></div>
		<div style="">
			<form id="fm-outorder" class="fm" method="post" novalidate>
				<div class="fitem divHidden">
					<input id="id" name="id" value="0">
				</div>
				<div id="div-paidMoney" class="fitem">
					<label><spring:message code="order.payMoney" />:</label> 
					<input id="paidMoney" name="paidMoney" class="easyui-numberbox" required="true" />
				</div>
			</form>
		</div>
	</div>
	<div id="dlg-buttons-update-paid">
		<a href="javascript:void(0)" id="update-paid-save" class="easyui-linkbutton"
			iconCls="icon-ok" onclick="saveModel('#dg-outorder', '#dlg-update-paid', '#fm-outorder')"><spring:message code="save" /></a> 
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel" onclick="javascript:$('#dlg-update-paid').dialog('close')"><spring:message code="cancel" /></a>
	</div>
	<!-- update paid money -->
	
	<!-- update status -->
	<div id="dlg-update-status" class="easyui-dialog"
		style="width: 400px; height: 215px; padding: 0px" closed="true"
		buttons="#dlg-buttons-update-status" data-options="modal:true">
		<div style="">
			<form id="fm-outorder" class="fm" method="post" novalidate>
				<div class="fitem">
					<label style="width:60px;">订单号:</label> 
					<input id="id" name="id" readonly="readonly" style="width:210px; border:none;">
				</div>
				<div class="fitem">
					<label style="width:60px;">客户:</label> 
					<input id="customerName" name="customerName" readonly="readonly" style="width:210px; border:none;">
				</div>
				<div class="fitem">
					<label style="width:60px;"><spring:message code="order.statusCode" />:</label> 
					<select id="orderStatus" name="statusCode" class="easyui-combobox" style="width:210px" editable="false" panelHeight="auto">
						<option value="NEW" selected="selected"><spring:message code="order.option.new" /></option>
						<!--<option value="RETURN"><spring:message code="order.option.return" /></option>-->
						<option value="CANCEL"><spring:message code="order.option.cancel" /></option>
						<option value="FINISHED"><spring:message code="order.option.finished" /></option>
					</select>
				</div>
				<div class="fitem">
					<label style="width:60px;">备注:</label> 
					<input id="comment" name="comment" class="easyui-validatebox" required="true" style="width:210px;">
				</div>
			</form>
		</div>
	</div>
	<div id="dlg-buttons-update-status">
		<a href="javascript:void(0)" id="" class="easyui-linkbutton"
			iconCls="icon-ok" onclick="saveModel('#dg-outorder', '#dlg-update-status', '#fm-outorder')"><spring:message code="save" /></a> 
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel" onclick="javascript:$('#dlg-update-status').dialog('close')"><spring:message code="cancel" /></a>
	</div>
	<!-- update status -->
	
	<!-- print order -->
	<div id="dlg-print-outorder" class="easyui-dialog" title="打印"
		style="width: 700px; height: 500px; padding: 10px 20px" closed="true"
		buttons="#dlg-buttons-print-outorder" data-options="modal:true">
		<div id="div-print-outorder-edit" style="">
			<div id="div-outorder-header" style="margin-bottom:5px;">
				<div id="div-print-outorder-title" style="height:30px; font-size:20px; font-weight:bold; text-align: center; margin-bottom:10px;">
					<input id="titleHeader" style="width: auto;" />
					<span id="titleSpan"></span>
				</div>
				<table style="width:100%">
					<tr>
						<td width="40%">客户:&nbsp;<span style="width:80%" id="customer"></span></td>
						<td width="30%">联系人:&nbsp;<input style="width:70%" type="text" id="contact" name="contact"/></td>
						<td width="30%">手机:&nbsp;<input style="width:70%" type="text" id="phone" name="phone"/></td>
					</tr>
					<tr>
						<td>地址:&nbsp;<input style="width:80%" type="text" id="address" name="address"/></td>
						<td>创建日期:&nbsp;<span style="width:60%" id="createDate"></span></td>
						<td>订单号:&nbsp;<span style="width:70%" id="orderId"></span></td>
					</tr>
				</table>
			</div>
			<div id="outorder-table" style="margin-bottom:5px;"></div>
			<div id="div-outorder-footer">
				<table style="width:100%">
					<tbody>
						<tr>
							<td>经手人:&nbsp;<span style="width:70%" id="user"></span></td>
							<td>客户签字:&nbsp;<span style="width:60%" id="customerSign"></span></td>
							<td>日期:&nbsp;<span style="width:70%" id="signDate"></span></td></tr>
						<tr>
							<td colspan="3"><input style="width:95%" type="text" id="attachment" name="attachment" value="<%=MessageProperties.getConfig (ComponentConstants.PRINT_ORDER_FOOTER) %>"/></td>
						</tr>
					</tbody>
				</table>
			</div>
		</div>
		<div id="div-print-outorder" style="display:none">
			<div id="div-outorder-header" style="margin-bottom:5px;">
				<div id="div-print-outorder-title" style="height:30px; font-size:20px; font-weight:bold; text-align: center; margin-bottom:10px;"></div>
				<table style="width:100%; font-size:12px;">
					<tr>
						<td width="40%">客户:&nbsp;<span id="customer"></span></td>
						<td width="30%">联系人:&nbsp;<span id="contact"></span></td>
						<td width="30%">手机:&nbsp;<span id="phone"></span></td>
					</tr>
					<tr>
						<td>地址:&nbsp;<span id="address"></span></td>
						<td>创建日期:&nbsp;<span id="createDate"></span></td>
						<td>订单号:&nbsp;<span id="orderId"></span></td>
					</tr>
				</table>
			</div>
			<div id="outorder-table" style="margin-bottom:5px; font-size:12px;"></div>
			<div id="div-outorder-footer">
				<table style="width:100%; font-size:12px;">
					<tbody>
						<tr>
							<td>经手人:&nbsp;<span id="user"></span></td>
							<td>客户签字:&nbsp;<span id="customerSign"></span></td>
							<td>日期:&nbsp;<span id="signDate"></span></td></tr>
						<tr>
							<td colspan="3"><span id="attachment"></span></td>
						</tr>
					</tbody>
				</table>
			</div>
		</div>
	</div>
	<div id="dlg-buttons-print-outorder">
		<a href="javascript:void(0)" id="" class="easyui-linkbutton"
			iconCls="icon-print" onclick="printOrder()"><spring:message code="print" /></a> 
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel" onclick="javascript:$('#dlg-print-outorder').dialog('close')"><spring:message code="cancel" /></a>
	</div>
	<!-- print order -->